/*******************************************************************************
 * Copyright (c) Jonathan Buck - jonbuck16@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    jonbuck16@gmail.com - initial API and implementation
 *******************************************************************************/
package net.jonbuck.tassoo.ui.filter;

import net.jonbuck.tassoo.model.Task;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

/**
 * 
 * 
 * @since 1.0.0
 */
public class TaskFilter extends ViewerFilter {

	/** .. */
	private IPreferencesService preferenceService;

	/**
	 * 
	 */
	public TaskFilter() {
		preferenceService = Platform.getPreferencesService();
	}

	/**
	 * 
	 */
	public boolean select(Viewer viewer, Object parentElement, Object element) {
		if (preferenceService.getBoolean("net.jonbuck.tassoo", "tasks.filter.complete", false, null)) {
			Task task = (Task) element;
			if (task.getStatus().getAssociatedPercentage() == 100) {
				return false;
			}
		}
		return true;
	}
}
